﻿//Login
$(function () {
    $("#signin").click(function () {
        SignIn();
    });

    $("#form").keypress(function (event) {
        if (event.which == '13') {
            SignIn();
        }
    });

    Email: $("#Email").focus();
});

function SignIn() {

    $("#signin").hide();

    var input = {
        Email: $("#Email").val(),
        Password: $("#Password").val(),
        RememberMe: $("#RememberMe").is(":checked")
    };

    Ajax({
        url: "/Security/TryLogin",
        data: JSON.stringify(input),
        success: function (data) {
            if (data.IsValid == true) {
                var returnurl = getQuerystring('ReturnUrl');
                location.href = returnurl == "" ? "/MyAdams" : unescape(returnurl);
            } else {
                ShowValidationErrors(data, { "": "" });
            }
        },
        complete: function () {
            $("#signin").show();
        }
    });
}
